package com.insurance.controller;

import com.insurance.common.ResponseData;
import com.insurance.common.ResultData;
import com.insurance.pojo.Brand;
import com.insurance.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: drc
 * Date: 2020/10/26 21:36
 * Description:
 * Version: V1.0
 */
@Controller
@RequestMapping(value = "/brand")
@Api(value = "品牌信息",tags = "品牌数据接口API")
public class BrandController {
    @Autowired
    private BrandService brandService;
    @RequestMapping(value = "/addBrand.do",method = RequestMethod.POST)
    @ApiOperation(value = "添加品牌信息接口",notes = "根据提交信息添加品牌",httpMethod = "post", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="添加成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData addBrand(@RequestBody Brand brand){
        ResultData resultData = new ResultData();
        int result =  brandService.addBrand(brand);
        if(result > 0){
            resultData.setCode(200);
            resultData.setMsg("添加成功");
        }else {
            resultData.setCode(500);
            resultData.setMsg("添加失败");
        }
        return resultData;
    }
    @RequestMapping(value = "/updateBrand.do",method = RequestMethod.POST)
    @ApiOperation(value = "修改品牌信息接口",notes = "根据提交信息修改品牌",httpMethod = "post", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="修改成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData updateBrand(@RequestBody Brand brand){
        ResultData resultData = new ResultData();
        int result =  brandService.updateBrand(brand);
        if(result > 0){
            resultData.setCode(200);
            resultData.setMsg("修改成功");
        }
        return resultData;
    }
    @RequestMapping(value = "/findBrand.do",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有品牌信息接口",notes = "查询所有品牌",httpMethod = "get", response = ResultData.class)
    @ApiResponses({
            @ApiResponse(code=200,message="查询成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    @ResponseBody
    public ResultData findBrand(){
        ResultData resultData = new ResultData();
        List<Map> brandList=brandService.findBrand();
        resultData.setCode(200);
        resultData.setMsg("查询成功");
        resultData.setData(brandList);
        return resultData;
    }
}
